//
//  stars.m
//  项目一
//
//  Created by nick on 15/7/21.
//  Copyright (c) 2015年 nick. All rights reserved.
//

#import "stars.h"
#import "UIViewExt.h"
@implementation stars{
    UIImage *image1;
    UIImage *image2;
    CGRect myframe;
}
- (void)_createStars{
    image1 = [UIImage imageNamed:@"yellow"];
    image2 = [UIImage imageNamed:@"gray"];
    
    _grayView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image2.size.width*5, image2.size.height)];
    _grayView.backgroundColor = [UIColor colorWithPatternImage:image2];
    [self addSubview:_grayView];
    
    _yellowView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image1.size.width*5*_average/10, image1.size.height)];
    _yellowView.backgroundColor = [UIColor colorWithPatternImage:image1];
    [self addSubview:_yellowView];
}
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    myframe = frame;
    if (self) {
        [self _createStars];
    }
    return self;
}
- (void)setAverage:(float)average{
    _average = average;
    [self setNeedsLayout];
}
- (void)layoutSubviews{
    CGFloat scale = myframe.size.height/image1.size.height;
    _yellowView.frame = CGRectMake(0, 0, image1.size.width*5*_average/10, image1.size.height);
    _yellowView.transform = CGAffineTransformMakeScale(scale, scale);
    _grayView.transform = CGAffineTransformMakeScale(scale, scale);
   
    CGRect frame = _yellowView.frame;
    frame.origin = CGPointZero;
    _yellowView.frame = frame;
    frame = _grayView.frame;
    frame.origin = CGPointZero;
    _grayView.frame = frame;
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
